package com.shxzz.easy12306.services.user.service.handler.filter.user;

import com.shxzz.easy12306.framework.starter.convention.exceptions.ClientException;
import com.shxzz.easy12306.services.user.common.enums.UserRegisterErrorCode;
import com.shxzz.easy12306.services.user.dto.req.UserRegisterReqDTO;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 用户必要注册参数非空校验
 * @author shxzz
 * @create 2024-02-27-21:49
 */
@Component
public class UserRegisterParamNotNullChainHandler implements UserRegisterFilter{
    @Override
    public void handler(UserRegisterReqDTO requestParam) {
        if(Objects.isNull(requestParam.getUsername())) throw new ClientException(UserRegisterErrorCode.USER_NAME_NOTNULL);
        if(Objects.isNull(requestParam.getPassword())) throw new ClientException(UserRegisterErrorCode.PASSWORD_NOTNULL);
        if(Objects.isNull(requestParam.getRealName())) throw new ClientException(UserRegisterErrorCode.REAL_NAME_NOTNULL);
        if(Objects.isNull(requestParam.getPhone())) throw new ClientException(UserRegisterErrorCode.PHONE_NOTNULL);
        if(Objects.isNull(requestParam.getIdType())) throw new ClientException(UserRegisterErrorCode.ID_TYPE_NOTNULL);
        if(Objects.isNull(requestParam.getIdCard())) throw new ClientException(UserRegisterErrorCode.ID_CARD_NOTNULL);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
